#/usr/bin/env python
"""
This simple example is used for the line-by-line tutorial
that comes with pygame. It is based on a 'popular' web banner.
Note there are comments here, but for the full explanation, 
follow along in the tutorial.
"""

#MYCOMMENT
# sto aggiungendo un commento in Italiano


#Import Modules
import os, pygame
from pygame.locals import *
from functions import *
import random as rand

#  Ahmad is awesome
class Hacker(pygame.sprite.Sprite):
    """moves a hacker critter across the screen. it can spin the
       hacker when it is poked."""
    def __init__(self):
        pygame.sprite.Sprite.__init__(self) #call Sprite intializer
        self.image, self.rect = load_image('thw.png', -1)
        screen = pygame.display.get_surface()
        self.area = screen.get_rect()
        self.rect.topleft = (10,(screen.get_height()/2))
        self.move = 4
        self.fall = 2*rand.random()
        self.dizzy = 0

    def update(self):
        "walk or spin, depending on the hackers state"
        if self.dizzy:
            self._spin()
        else:
            self._walk()

    def _walk(self):
        "move the hacker across the screen, and turn at the ends"
        newpos = self.rect.move((self.move, self.fall))
        if self.rect.left < self.area.left or \
           self.rect.right > self.area.right:
            self.move = -self.move
            newpos = self.rect.move((self.move,self.fall))
            self.image = pygame.transform.flip(self.image, 1, 0)
        if self.rect.bottom > self.area.bottom or \
           self.rect.top < self.area.top:
            self.fall = -self.fall
            newpos = self.rect.move((self.move, self.fall))
            self.image = pygame.transform.flip(self.image, 0, 1)
        self.rect = newpos

    def _spin(self):
        "spin the hacker image"
        center = self.rect.center
        self.dizzy = self.dizzy + 12
        if self.dizzy >= 360:
            self.dizzy = 0
            self.image = self.original
        else:
            rotate = pygame.transform.rotate
            self.image = rotate(self.original, self.dizzy)
        self.rect = self.image.get_rect(center=center)

    def poked(self):
        "this will cause the hacker to start spinning"
        if not self.dizzy:
            self.dizzy = 1
            self.original = self.image

